var pos = 0;
var totalSlides = $('#slider-wrap ul li').length;
var sliderWidth = $('#slider-wrap').width();
$(document).ready(function() {
    $('#slider-wrap ul#slider').width(sliderWidth * totalSlides);
    $('#next').click(function() {
        slideRight();
    });
    $('#previous').click(function() {
        slideLeft();
    });
    var autoSlider = setInterval(slideRight, 3000);
    $.each($('#slider-wrap ul li'),function() {
        var c = $(this).attr("data-color");
        $(this).css({
            "background":"url("+c+") no-repeat center scroll",
            "background-size":"cover"
        });
        var li = document.createElement('li');
        $('#pagination-wrap ul').append(li);
    });
    countSlides();
    pagination();
    $('#slider-wrap').hover(function() {
            $(this).addClass('active');
            clearInterval(autoSlider);
        },
        function() {
            $(this).removeClass('active');
            autoSlider = setInterval(slideRight, 3000);
        });
});
function slideLeft() {
    pos--;
    if (pos == -1) {
        pos = totalSlides - 1;
    }
    $('#slider-wrap ul#slider').css('left', -(sliderWidth * pos));
    countSlides();
    pagination();
}
function slideRight() {
    pos++;
    if (pos == totalSlides) {
        pos = 0;
    }
    $('#slider-wrap ul#slider').css('left', -(sliderWidth * pos));
    countSlides();
    pagination();
}
function countSlides() {
    $('#counter').html(pos + 1 + ' / ' + totalSlides);
}
function pagination() {
    $('#pagination-wrap ul li').removeClass('active');
    $('#pagination-wrap ul li:eq(' + pos + ')').addClass('active');
}

function tableListFun(pageNo){
    var id = window.document.getElementById("indexListTabs");

    $.ajax({
        url: get_newsAll_interface,
        type:'get',
        dataType:'json',
        xhrFields:{
            withCredentials:true
        },
        crossDomain:true,
        data:{
            currentPage:pageNo
        },
        success: function(data) {
            if(data.code==200){
                innerTbody(data,id, tableListFun);
            }else{
                $.message(data.msg);
            }
        },
        error: function (error) {
            $.message("链接超时，请刷新...");
        }
    });
}

tableListFun(1);

function innerTbody(data,id, func){
    var page = data.data.num;
    var currentPage = data.data.currentPage;
    var tml = "";

    $(".pageNum em").html(page);
    if(page>0){
        setPagination(page,currentPage, func);
        var lists = data.data.list;
        $('#pagination').show();
        for (x in lists) {
            tml += "<tr>"+
                "<td>"+(parseInt(x)+1)+"</td>"+
                '<td><a href="answer.html?newsId='+lists[x]["id"]+'" class="c-009 f-14">'+lists[x]["title"]+'</a></td>'+
                "<td>"+lists[x]["newsCreateTime"]+"</td>"+
                "</tr>" ;
        }
    }else{
        $('#pagination').hide();
    }
    id.innerHTML = tml;
}